package com.tgy.controller;

import com.tgy.entity.User;
import com.tgy.service.UserService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
public class UserDoController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public User selectOne(Integer id) {
        return this.userService.queryById(id);
    }
    /**
     *
     * @param login 账户
     * @param password 密码
     * @return 用户列表
     */
    @RequestMapping("/queryAll")
    public List<User> quaryAll(@RequestParam("login") String login, @RequestParam("password") String password){
        User user = new User();
        user.setLogin(login);
        user.setPassword(password);
        if(this.userService.queryAll(user).isEmpty()){
            System.out.println("密码或者账户名错误");
        };
        return this.userService.queryAll(user);
    }

    /**
     *
     * @param offset 起始
     * @param limit 个数
     * @return 用户列表
     */
    @RequestMapping("queryAllByLimit")
    public List<User> queryAllByLimit(int offset, int limit){
        return this.userService.queryAllByLimit(offset,limit);
    }

    @RequestMapping(value = "/getUserList.do")
    @ResponseBody
    public Map<String, Object> getUserList(User user) {
        return userService.queryAllByUser(user);
    }


    @RequestMapping("web")
    public String web( Model model){
        User user = new User();
        model.addAttribute("msg","传值");
        model.addAttribute("user", user);
        List<User> userList= (List<User>) userService.queryAll(new User());
        model.addAttribute("userList",userList);
        return "666";
    }
@RequestMapping("login.do")
    public String checkLogin(){
        return "999";
    }
}
